import Vue from 'vue'
import Vuex from 'vuex'
import shouye from '../store/modules/shouye'
import user from "../store/modules/user";
import xieyi from "./modules/xieyi";
import produceList from "./modules/produceList";
import persisted from "vuex-persistedstate";
import smrz from './modules/smrz'
import { jiami, jiemi } from "../utils/aeskey";
import { getwwcform } from "../api/index";
Vue.use(Vuex)

export default new Vuex.Store({
    plugins: [persisted()],
    state: {
        //loadding
        isShow: false,
        //判断是否登录
        isLogin: false,
        //未完成表单数据
        formData: [],
        formLength: '',
        //MyOrder的状态
        count: 1,
        //还款订单编号
        orderId: '',
        //还款总额
        payMount: '',
        endTime: '', //还款时间
    },
    getters: {},
    mutations: {
        //改变count
        changeCount(state, payload) {
            state.count = payload
        },
        // 展示loadding方法
        showLoading(state) {
            state.isShow = true
        },
        // 影藏loadding方法
        hideLoading(state) {
            state.isShow = false
        },
        //登录中
        logining(state) {
            state.isLogin = true
        },
        //退出登录的状态
        leaving(state) {
            state.isLogin = false
        },
        setFormData(state, payload) {
            state.formData = payload
            state.formLength = state.formData.length
            console.log(state.formLength, 'formLength')
        },
        //改变还款订单列表
        changeOrderId(state, payload) {
            state.orderId = payload
        },
        // 改变还款总额
        changepayMount(state, payload) {
            state.payMount = payload
        },
        //改变产品名称
        changeEndTime(state, payload) {
            state.endTime = payload
        }
    },
    actions: {
        //获取一个未完成的表单
        async weiwancehngform(content) {
            const form = {
                model: {
                    nodeType: ''
                }
            }
            const res = await getwwcform(jiami(form))
            const result = jiemi(res.data)
            console.log('未完成的表单vuex', result)
            content.commit('setFormData', result.model.forms)
        }
    },
    modules: {
        shouye: shouye,
        user: user,
        xieyi,
        produceList,
        smrz
    }
})